package com.tanzeer.deliverytracker.adapter;

import java.util.List;

import com.tanzeer.deliverytracker.R;
import com.tanzeer.deliverytracker.models.DelivaryTracks;
import com.tanzeer.deliverytracker.utils.PreferenceConnector;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

public class IntervalListAdapter extends ArrayAdapter<String> {

	private Context context;

	public IntervalListAdapter(Context context, int textViewResourceId,
			List<String> items) {
		super(context, textViewResourceId, items);
		this.context = context;
	}

	private class ViewHolder {

		TextView name;
		RadioButton radioButton;

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		LayoutInflater mInflater = (LayoutInflater) context
				.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.interval_list_row,
					null);
			holder = new ViewHolder();
			holder.name = (TextView) convertView
					.findViewById(R.id.textView1);
			int id = Resources.getSystem().getIdentifier(
					"btn_check_holo_light", "drawable", "android");
			holder.radioButton = (RadioButton) convertView
					.findViewById(R.id.radioButton1);
			/*((RadioButton) convertView.findViewById(R.id.radioButton1))
			.setButtonDrawable(id);*/
			
			convertView.setTag(holder);

		} else
			holder = (ViewHolder) convertView.getTag();
		// Log.v("msg","hello");
		String object = getItem(position);
		String str=PreferenceConnector.readString(context,PreferenceConnector.Interval,"1 Hour (recommended)");
		if(object.equals(str))
			holder.radioButton.setChecked(true);
		else
			holder.radioButton.setChecked(false);
			
	
		holder.name.setText(object);
		
		return convertView;

	}

}
